/** 判断屏幕大小 */
export function judgeBigScreen() {
  //，这里根据返回值 true 或false ,返回true的话 则为全面屏
  let result = false;
  const rate = window.screen.height / window.screen.width;
  let limit = window.screen.height == window.screen.availHeight ? 1.8 : 1.65; // 临界判断值

  if (rate > limit) {
    result = true;
  }
  return result;
}

export const isX = judgeBigScreen()

// 验证手机号的格式
export function phoneValid(phone) {
  const reg = /^1[3456789]\d{9}$/
  return reg.test(phone)
}

export function dataURLtoFile(dataurl, filename) {//将base64转换为文件
  var arr = dataurl.split(','), mime = arr[0].match(/:(.*?);/)[1],
  bstr = atob(arr[1]), n = bstr.length, u8arr = new Uint8Array(n);
  while(n--){
      u8arr[n] = bstr.charCodeAt(n);
  }
  return new File([u8arr], filename, {type:mime});
}
// 验证身份证的格式
export function idCardValid(idCard) {
  const reg = /(^\d{15}$)|(^\d{17}([0-9]|X)$)/
  return reg.test(idCard)
}

export function getUrlParam(name) {
  //构造一个含有目标参数的正则表达式对象
  var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
  //匹配目标参数
  var r = window.location.search.substr(1).match(reg);
  //返回参数
  if (r != null) {
      return unescape(r[2]);
  } else {
      return null;
  }
}

export function guid() {
  function S4() {
    return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
  }
  return (
    S4() +
    S4() +
    '-' +
    S4() +
    '-' +
    S4() +
    '-' +
    S4() +
    '-' +
    S4() +
    S4() +
    S4()
  );
}
